<template>
  <div class="login">
    <van-card
      class="login-form"
      thumb="/logo.png"
    >
      <van-form
        @submit="handleLogin"
        slot="desc"
      >
        <van-field
          v-model="loginForm.account"
          label="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="loginForm.password"
          label="密码"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-button
          type="primary"
          block
          :loading="isLoading"
          native-type="submit"
        >
          登录
        </van-button>
      </van-form>
    </van-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      isLoading: false,
      loginForm: {
        account: 'admin',
        password: '123456'
      }
    }
  },
  methods: {
    async handleLogin() {
      this.isLoading = true
      this.$store.dispatch('user/login', this.loginForm).then((res) => {
        this.$router.push('/')
        this.isLoading = false
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.login {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url(../../assets/imgs/bg.jpg);
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  .login-form {
    width: 400px;
  }
  ::v-deep .van-card {
    background-color: rgba(0, 0, 0, 0.5);
  }

  ::v-deep .van-card {
    padding: 0;
    .van-card__header {
      align-items: center;
      justify-content: center;
      .van-card__thumb {
        margin-right: 0;
      }
    }
  }
}
</style>
